//
//  ZZCMainController.swift
//  weibo
//
//  Created by zhangzuchao on 17/3/26.
//  Copyright © 2017年 zhangZuChao. All rights reserved.
//

import UIKit
import SVProgressHUD
class ZZCMainController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let tabBar = ZZCTabBar()
        
        //闭包回调
        tabBar.didSelectedButton = {[weak self] in
            //此处加weak防止重复循环引用
            if !ZZCUserAccountViewModel.sharedViewModel.isLogin {
                SVProgressHUD.showError(withStatus: "请先登录,亲~")
                return
            }
            if let weakSelf = self {
                //  代码执行到此,表示登录成功
                let composeView = ZZCComposeView()
                //  显示罩层
                composeView.show(target: weakSelf)
                
                
            }
        }

        
        self.setValue(tabBar, forKey: "tabBar")
        
        //首页
        addChildViewController(childController: ZZCHomeController(), imageName: "tabbar_home", title: "首页")
        //消息
        addChildViewController(childController: ZZCMessageController(), imageName: "tabbar_message_center", title: "消息")
        //发现
        addChildViewController(childController: ZZCDiscoverController(), imageName: "tabbar_discover", title: "发现")
        //我的
        addChildViewController(childController: ZZCMineController(), imageName: "tabbar_profile", title: "我的")
        
    }
    
        
        
        
        //重写添加子控制器的方法
        func addChildViewController(childController: UIViewController, imageName:String, title:String){
        
        //设置tabbaritem的图片
           childController.tabBarItem.image = UIImage(named: imageName)
            //设置选中图片,设置渲染模式使用原始图片方式显示
            childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(.alwaysOriginal)
            //设置文字颜色
            childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orange], for: .selected)
            //设置文字大小
            childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 12)], for: .normal)
            //设置标题
            childController.tabBarItem.title = title
            childController.navigationItem.title = title
            //创建导航控制器
            let nav = ZZCNavigationController(rootViewController: childController)
            //添加子控制器
            addChildViewController(nav)
        }
        
        
     
    
 
}






















